The present invention relates to a flash ROM management method and apparatus in, e.g., a computer. The present invention also relates to an IC card and an electronic camera using a flash ROM.
Various types of flash ROMs are currently available and roughly classified into those developed for flash disks and those developed for BIOSs of personal computers.
The erase unit of the former flash ROM is 512 bytes which is a general erase unit of hard disks. Therefore, this flash ROM is highly compatible with file systems. The erase unit of the latter flash ROM is a large block unit, e.g., 64 KB. Also, some of flash ROMs of this type require a voltage of 12 V or higher as a write voltage as in the case of PROMS. Although flash ROMs of the latter type are readily obtainable because they are inexpensive, they are not highly compatible with file systems and hence cannot be used as particularly small-capacity recording media.
As described above, flash ROMs designed for BIOSs are inexpensive and therefore readily available although they have a large erase unit and are not highly compatible with file systems. Accordingly, if this type of flash ROMs can be applied to file systems, inexpensive small-capacity recording media can be provided.
IC cards inserted into host apparatuses are widely used as auxiliary storages for storing various data. For example, an IC card which only reads out data, such as an IC card storing font data, incorporates a ROM storing necessary data. An IC card in which data is rewritable generally incorporates a RAM, and a data read/write operation is executed by using the RAM. Since, however, a RAM cannot hold data without being backed up by a power supply, a power supply is incorporated in an IC card if it is necessary to hold data.
A flash ROM is an example of the data rewritable ROM. Various types of flash ROMs are presently available and roughly divided into a category developed for flash disks and a category developed for BIOSs of personal computers.
Generally, IC cards require a dedicated interface, and so it is not possible to use interfaces for common file systems (e.g., hard disks and floppy disks) which host apparatuses have.
In electronic cameras, image data obtained by photography is stored in a storage medium such as an internal DRAM or an external memory card. These storage media need to be constantly backed up by, e.g., batteries since the stored contents disappear if the supply of power is cut off. A magnetic disk is an example of a storage medium which does not require electrical backup to hold the stored contents. However, magnetic disk devices are relatively large and therefore impair the portability of electronic cameras. Another example of a storage medium which need not be electrically backed up to hold the stored contents is a rewritable ROM, i.e., a flash ROM.
As described above, flash ROMs designed for BIOS have a large erase unit and a low compatibility with file systems but are readily obtainable because they are inexpensive. Therefore, if this type of flash ROMs can be applied to system files, it is possible to provide inexpensive, small-capacity, and small-sized recording media which do not require a power supply to hold the stored contents. This is convenient as a storage medium of an electronic camera.
It is an object of the present invention to provide a flash ROM management method and apparatus capable of making a flash ROM with a large erase unit compatible with a file system.
The present invention has been made in consideration of the above situation, and has as its object to provide a flash ROM management method and apparatus which can manage a data readxe2x80xa2write unit (storage unit) smaller than an erase unit in a flash ROM and can therefore make a flash ROM with a large erase unit compatible with a file system.
When the above object is achieved, even a flash ROM designed for BIOS and having an erase unit of 64 KB can provide a file system with services similar to those provided by a hard disk.
To achieve the above object, a flash ROM management apparatus according to the present invention comprises access means for accessing a plurality of data areas and management areas corresponding to the data areas formed in a flash ROM, writing means for receiving a write instruction containing specification information which specifies a data write destination, writing data in one of the data areas, and writing the specification information in a management area corresponding to the data area, and reading means for receiving a read instruction containing specification information which specifies a data read source, retrieval-accessing a management area in which the specification information is stored, and reading out data stored in a data region corresponding to the retrieval-accessed management area.
Preferably, the management area stores state information indicating whether a corresponding data area is writable, and the writing means retrieval-accesses a management area whose state information indicates a writable state, writes the specification information in the retrieval-accessed management area, and writes data in a data area corresponding to the retrieval-accessed management area. When data in the flash ROM is updated, for example, the updated data can be written in an appropriate data area by checking the state information.
Preferably, the management area stores state information indicating one of at least three states, i.e., an unused state indicating that a corresponding data area is writable, a busy state indicating that data written in the data area is valid, and a used state indicating that the data written in the data area is invalid, and the writing means retrieval-accesses a management area whose state information indicates the unused state, writes the specification information and data in the retrieval-accessed management area and a corresponding data area, respectively, and changes the state information of the management area to the busy state. Since one of the three states, the busy, used, and unused states, is indicated for each data area, an area in which data can be written and an area in which valid data exists can be known by checking the state information. Consequently, the stored data in the flash ROM can be more appropriately managed.
Preferably, the writing means retrieval-accesses a management area having specification information contained in the write instruction and changes state information of the retrieval-accessed management area to the used state. When the contents of a data area specified by certain specification information are updated, it is possible to clearly show that the data is the one before the updating (i.e., unnecessary data). Consequently, appropriate storage management can be performed.
Preferably, the apparatus further comprises moving means for retrieval-accessing all management areas whose state information indicates the busy state in an erase block as an erase unit of the flash ROM and moving contents of the retrieval-accessed management areas and corresponding data areas to the outside of the erase block, and erasing means for erasing the erase block after the execution of the moving means. Consequently, a data area in the used state in which data is made invalid by, e.g., updating of the data, can be changed into a writable unused data area. This improves the utilization of the flash ROM.
Preferably, a moving destination of the contents of the management area and the data area which are to be moved by the moving means is another erase block in the flash ROM. Since data is moved inside the flash ROM, the data is safely held even if the power supply is turned off.
Preferably, the moving means determines the moving destination as a random access memory when no writable data area exists in other erase blocks of the flash ROM. Even when all data areas in the flash ROM are busy or already used, an unused data area can be formed in the flash ROM. As a consequence, the flash ROM can be efficiently used.
Preferably, a moving destination of the contents of the management area and the data area which are to be moved by the moving means is a random access memory. This is so because data can be moved rapidly.
Preferably, the management area and the corresponding data area exist in the same erase block of the flash ROM. This is because a management area and a corresponding data area can be simultaneously erased.
Preferably, the apparatus further comprises control means for evaluating a storage efficiency of the flash ROM and controlling the execution of the moving means and the erasing means on the basis of the evaluation result. As a consequence, the erase processing for forming an unused area can be executed at a proper timing.
Preferably, the control means evaluates the storage efficiency by comparing a size of management areas whose state information indicates the used state with a size of management areas whose state information indicates the unused state. This allows very easy and appropriate evaluation of the storage efficiency.
Preferably, the writing means starts writing data in the flash ROM and at the same time transfers the control of a CPU to another processing. This is because a data write operation to the flash ROM requires a predetermined time, and this write time can be allocated to another processing.
Preferably, prior to writing data in the flash ROM, the writing means checks whether the previous data write operation to the flash ROM is completed.
As described above, to update data stored in a flash ROM, the data is written in another data area because data cannot be overwritten in a flash ROM. As a result, the data before the updating becomes invalid, and the utilization of a flash ROM decreases due to accumulation of these invalid data. Therefore, to manage access to a flash ROM adapted to a file system, it is essential to erase invalid data in the flash ROM.
As described above, to manage and apply a flash ROM having a large erase unit to a file system, it is essential to execute an erase operation in the erase unit. To perform this erase operation, valid data in the erase unit must be retained. As a method of retaining data, it is possible to move the data to the outside of the erase unit. The method is required to have a high processing speed as well as the safety of the retained data.
It is, therefore, another object of the present invention to provide a flash ROM management method and apparatus capable of highly safely and rapidly retaining valid data existing in an erase unit to be erased.
To achieve the above object, a flash ROM management apparatus comprises managing means for forming a plurality of storage blocks each consisting of a data area and a management area corresponding to the data area in a flash ROM, storing state information indicating a storage state of the data area of each storage block in the management area of the storage block, and managing access to the flash ROM on the basis of the state information, first erasing means for extracting, from one erase block of the flash ROM, on the basis of the state information, a storage block in which valid data exists in the data area, moving contents of the extracted storage block to a random access memory, and erasing the erase block, second erasing means for extracting, from a plurality of erase blocks, on the basis of the state information, storage blocks in which valid data exists in the data area, moving contents of the extracted storage blocks to the random access memory, and erasing the erase blocks, and executing means for selecting one of the first erasing means and the second erasing means and executing the erase operation on the basis of the type of power supply of an apparatus into which the flash ROM is incorporated.
Preferably, the first erasing means has another erase block of the flash ROM and a random access memory as a moving destination to which the contents of the storage block containing valid data in one erase block are moved, and preferentially selects another erase block of the flash ROM. This is because the safety is further increased by moving the contents of a storage block to the flash ROM.
Preferably, the executing means uses the first erasing means when the power supply is a battery and uses the second erasing means when the power supply is an AC adaptor. When the power supply is a battery, there is the possibility that the supply of power is cut off due to, e.g., removal of the battery. Accordingly, the safety is assigned priority by saving data to a random access memory as seldom as possible. When the power is supplied by an AC adaptor, data in a plurality of erase units is saved to a random access memory, and these erase units are erased. This gives priority to the rapidness and the efficiency of the erase processing.
If an erase unit to be erased is chosen on the basis of only the amount of invalid data in the erase unit, erase units are not evenly erased. This unevenness varies the service lives of the erase units.
It is, therefore, still another object of the present invention to provide a flash ROM management method and apparatus and a computer control apparatus capable of reducing variations in the erase counts in erase units in a management system by which a flash ROM can be adapted to a file system.
To achieve the above object of the present invention, a flash ROM management apparatus comprises managing means for forming a plurality of storage blocks each consisting of a data area and a management area corresponding to the data area in a flash ROM, storing state information indicating a storage state of the data area of each storage block in the management area of the storage block, and managing access to the flash ROM on the basis of the state information, erasing means for extracting, from an erase block of the flash ROM, on the basis of the state information, a storage block in which valid data exists in the data area, moving contents of the extracted storage block, and erasing the erase block, count means for counting the number of erase operations performed by the erasing means as an erase count and storing the erase count in a storage area of an erase block, and determining means for determining an erase block to be erased by the erasing means on the basis of the erase count.
Preferably, the determining means determines, as an object to be erased, an erase block having a small erase count of erase blocks containing invalid data. When an erase block containing invalid data and having a small erase count is preferentially erased, the erase counts of erase blocks can be dispersed. As a consequence, the rewrite durability can be dispersed.
As described above, in storage management by which a flash ROM is adapted to a file system, invalid data stored in the flash ROM must be erased. Accordingly, it is important to check whether data stored in a flash ROM is invalid data.
In general file systems, however, no processing is performed to actively release sectors in which data is made invalid by, e.g., erasure of files. In management of a flash ROM, the storage efficiency is maintained by erasing invalid data. Therefore, leaving invalid data unerased in a file system is unpreferable.
It is, therefore, still another object of the present invention to provide a flash ROM management method and apparatus and a computer control apparatus capable of releasing storage blocks equivalent to sectors and thereby efficiently erasing invalid data in a management system by which a flash ROM can be adapted to a file system.
It is still another object of the present invention to make it possible to detect a storage block in which data is to be invalidated on the basis of the contents of access from a file system to a flash ROM and discard (invalidate) the data in the storage block.
To achieve the above objects, a flash ROM management apparatus according to the present invention comprises managing means for forming a plurality of storage blocks each consisting of a data area and a management area corresponding to the data area in a flash ROM, storing state information indicating a storage state of the data area of each storage block in the management area of the storage block, and managing access to the flash ROM on the basis of the state information, and discarding means for discarding data stored in a designated storage block by updating the state information stored in the management area of the storage block to information indicating that the data in the storage block is invalid.
Preferably, the apparatus further comprises detecting means for detecting a storage block made unnecessary by access to the flash ROM, and the discarding means updates the state information of a storage block detected by the detecting means to information indicating that data in the storage block is invalid. Consequently, a storage block to be discarded can be automatically detected and discarded.
A data write or erase operation to a flash ROM is very-time-consuming processing with respect to the operating speed of a CPU. Accordingly, some countermeasure is necessary when access to a flash ROM is managed in multitask processing in which a plurality of tasks are executed in parallel.
It is, therefore, still another object of the present invention to provide a flash ROM management method and apparatus and a computer control apparatus capable of suitably applying a management system by which a flash ROM can be adapted to a file system to a multitask system.
It is still another object of the present invention to provide a flash ROM management method and apparatus which allow a plurality of tasks to efficiently perform write operations to a plurality of flash ROMs.
It is still another object of the present invention to make it possible to perform preprocessing of improving the processing speed of erase processing by using a task with a low priority.
To achieve the above objects, a flash ROM management apparatus according to the present invention is a flash ROM management apparatus in a system in which a plurality of tasks are executed in parallel, comprising managing means for forming a plurality of storage blocks each consisting of a data area and a management area corresponding to the data area in a flash ROM, storing state information indicating a storage state of the data area of each storage block in the management area of the storage block, and managing access to the flash ROM on the basis of the state information, and excluding means for inhibiting, when one of the storage blocks is accessed by one of the tasks, access from other tasks to the accessed storage block.
Preferably, the managing means retrieval-accesses an unused storage block and writes data in the retrieval-accessed storage block when access to the flash ROM is a data write operation, and the excluding means inhibits other tasks from retrieval-accessing unused storage blocks while the managing means is retrieval-accessing the unused storage block. This can prevent the same storage block from being retrieval-accessed by a plurality of tasks.
To achieve the above objects, a flash ROM management apparatus according to the present invention is a flash ROM management apparatus in a system capable of executing a plurality of tasks in parallel in accordance with priorities of the tasks, comprising managing means for forming a plurality of storage blocks each consisting of a data area and a management area corresponding to the data area in a flash ROM, storing state information indicating a storage state of the data area of each storage block in the management area of the storage block, and managing access to the flash ROM on the basis of the state information, preprocessing means for performing preprocessing of improving an erase speed for a storage block whose state information indicates invalid data, and executing means for executing the preprocessing means by assigning the execution to a task having a low priority of the plurality of tasks.
A data write or erase operation to a flash ROM is very-time-consuming processing with respect to the operating speed of a CPU. In addition, as described above, updating of data in a flash ROM accumulates unnecessary (invalid) data in the flash ROM. This decreases the utilization of the flash ROM.
It is, therefore, still another object of the present invention to provide a flash ROM management method and apparatus and a computer control apparatus in which information whose contents are frequently rewritten is stored in a cache memory to decrease the number of write operations to a flash ROM and reduce the increase in invalid data in the flash ROM.
To achieve the above object, a flash ROM management apparatus according to the present invention comprises managing means for forming a plurality of storage blocks each consisting of a data area and a management area corresponding to the data area in a flash ROM, storing state information indicating a storage state of the data area of each storage block in the management area of the storage block, and managing access to the flash ROM on the basis of the state information, first determining means for determining whether the storage block contains predetermined information to be buffered by using a cache, and buffer means for performing buffering for caching in units of storage blocks for the storage blocks determined by the first determining means to require buffering.
Preferably, the predetermined information is information which a file system uses to access the flash ROM. For example, information such as FAT data which a file system uses to access the flash ROM is frequently rewritten. Accordingly, when this information is cached it is possible to provide a cache having a high hit rate with a limited cache capacity.
Preferably, the buffer means manages the storage of the storage blocks by managing storage positions in units of storage blocks by using a one-way linear list structure. This is so because the internal data structure of the cache is simplified.
Preferably, the apparatus further comprises second determining means for determining, when the flash ROM is accessed, whether an accessed storage block contains the predetermined information. In this apparatus, when the second determining means determines that a storage block containing the predetermined information is accessed, the buffered contents of the buffer means are accessed. Since a storage block containing predetermined information is cached, the buffered contents (cached contents) are accessed when the storage block having the predetermined information is accessed.
As described above, the contents of a flash ROM can be erased only in an erase unit. Accordingly, to update data in a storage block in a flash ROM, the data in the storage block before the updating is invalidated, and the updated data is written in another block. As a consequence, invalid data accumulates in the flash ROM to decrease the utilization of the flash ROM. To prevent an event like this from occurring, it is necessary to save valid data in an erase block in which invalid data exists and then erase the erase unit, thereby rearranging the flash ROM.
While unused storage blocks exist in a flash ROM, updated data can be written in these unused storage blocks. However, if unused storage blocks are used up, a very large number of write operations take place to update data in one storage block. That is, if updating of data occurs in a storage block with no unused storage block being present, it is necessary to save all storage blocks in the erase unit, erase the erase unit, write all storage blocks, except the storage block in which the data updating has occurred, back into the flash ROM, and write the updated contents of the storage block in which the data updating has occurred. This significantly decreases the efficiency.
It is, therefore, still another object of the present invention to provide a flash ROM management method and apparatus and a computer control apparatus capable of preventing a decrease in the storage efficiency by preparing extra areas in addition to the total capacity of areas to be accessed to perform data read and write operations in a flash ROM.
To achieve the above object, a flash ROM management apparatus according to the present invention comprises managing means for forming a plurality of storage blocks each consisting of a data area and a management area corresponding to the data area in a flash ROM, storing state information indicating a storage state of the data area of each storage block in the management area of the storage block, and managing access to the flash ROM on the basis of the state information, saving means for extracting, from an erase block of the flash ROM, by referring to the state information in the management area, a storage block in which data in the data area is valid, and saving contents of the extracted storage block to the outside of the erase block, erasing means for erasing the erase block after the saving means has saved all storage blocks containing valid data in the erase block, and extra storage blocks in addition to the storage blocks to be accessed by the managing means.
Preferably, the storage area has a size of at least one erase block of the flash ROM. Consequently, unused areas corresponding to at least one erase block can be constantly reserved by the erase operation done by the erasing means.
It is still another object of the present invention to provide an IC card apparatus capable of managing a data readxe2x80xa2write unit (storage unit) smaller than an erase unit in a flash ROM incorporated in an IC card and thereby adapting a flash ROM with a large erase unit to a file system.
When this object is achieved, it is possible to provide services similar to those provided by a hard disk by using an IC card incorporating a flash ROM designed for, e.g., BIOS, and having an erase unit of 64 KB.
To achieve the above object, an IC card apparatus according to the present invention which is attached to a host apparatus and to which a data write/read operation can be performed in accordance with a request from the host apparatus, comprises a flash ROM managed by forming a plurality of data areas and management areas corresponding to the data areas in the flash ROM, writing means for receiving from the host apparatus a write instruction containing specification information which specifies a data write destination, writing data in one of the data areas, and writing the specification information in a management area corresponding to the data area, and reading means for receiving from the host apparatus a read instruction containing specification information which specifies a data read source, retrieval-accessing a management area in which the specification information is stored, and reading out data stored in a data region corresponding to the retrieval-accessed management area.
Preferably, a connecting portion to be attached to the host apparatus has compatibility with an interface for an external storage of the host apparatus, and the IC card apparatus further comprises interpreting means for interpreting various commands for an external storage of the host apparatus. This allows the file system of the host apparatus to access the IC card.
It is still another object of the present invention to provide an electronic camera capable of adapting a flash ROM with a large erase unit to a file system.
To achieve the above object, an electronic camera of the present invention for storing data in a flash ROM comprises a plurality of data areas and management areas corresponding to the data areas formed in the flash ROM, writing means for receiving a write instruction containing specification information which specifies a data write destination, writing data in one of the data areas, and writing the specification information in a management area corresponding to the data area, and reading means for receiving a read instruction containing specification information which specifies a data read source, retrieval-accessing a management area in which the specification information is stored, and reading out data stored in a data region corresponding to the retrieval-accessed management area.
Preferably, the camera further comprises timer means for performing self-timer photography, and the moving means and the erasing means are executed while the timer means is measuring a time. Since the moving means and the erasing means are executed during self-timer photography, the flash ROM can be rearranged without interfering with the operation of the electronic camera.
Preferably, the camera further comprises power supply managing means for managing the use of a power supply, and the power supply managing means allocates power of a power supply, which is used to perform at least one of charging of an electronic flash, driving of a mechanical portion, and driving of a CCD, to write access to the flash ROM. Since the power supply used to charge an electronic flash, drive a mechanical portion, or drive a CCD can be used to perform write access to the flash ROM, it is no longer necessary to prepare a dedicated power supply for a write operation to the flash ROM.
The power supply managing means time-divisionally allocates power supplied from the power supply to charging of an electronic flash, driving of a mechanical portion, driving of a CCD, and write access to the flash ROM. Since the power supply is time-divisionally allocated, the power supply can always be obtained after a short holding time. Consequently, various processing activities can be smoothly executed.
Other features and advantages of the present invention will be apparent from the following description taken in conjunction with the accompanying drawings, in which like reference characters designate the same or similar parts throughout the figures thereof.